import Mock from 'mockjs'
import {menuItems} from '@/config/menu'
import type {MenuItem} from '@/config/menu'

const {mock} = Mock

// 为菜单项添加缺失的字段
const enrichMenuItems = (items: MenuItem[]): MenuItem[] => {
    return items.map(item => {
        const enrichedItem: MenuItem = {
            ...item,
            permission: "sys:xxxx:list",
            sort: 1,
            createdTime: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss'),
            createdBy: 'admin',
            updatedTime: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss'),
            updatedBy: 'admin',
        };

        // 如果存在子菜单，递归处理
        if (enrichedItem.children && enrichedItem.children.length > 0) {
            enrichedItem.children = enrichMenuItems(enrichedItem.children);
        }

        return enrichedItem;
    });
};

// 使用拦截规则拦截命中的请求
mock("/api/menus", "get", {
    code: 200,
    data: {
        total: menuItems.length,
        list: enrichMenuItems(menuItems)
    }
}) 